﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Share;
using BUS;
using Entity;
using DevExpress.XtraGrid.Localization;

namespace SLMNG
{
    public partial class DlgSelectFoods : Form
    {
        string codeList = string.Empty;
        public DataTable dtResult;
        public DlgSelectFoods(string list)
        {
            InitializeComponent();
            codeList = list;
            this.Load += DlgSelectFoods_Load;
            dtResult = new DataTable();
        }

        void DlgSelectFoods_Load(object sender, EventArgs e)
        {
            try
            {
                GridLocalizer.Active = new MyGridLocalizer();
                LoadData();
            }
            catch (Exception ex)
            {
                MessageBox.Show(HandleException.HandleSQLException(ex.Message), this.Text);
            }
        }

        private void LoadData()
        {
            string[] arg = new string[] { "ItemCode" };
            object[] obj = new object[] { codeList };
            DataTable dt1 = CatalogueBase.GetData(ItemFood.STORE_SELECT_NOT_EXISTS, arg, obj).Tables[0];
            gridView.DataSource = dt1;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            dtResult = ((DataTable)gridView.DataSource).Clone();
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            for (int i = 0; i < gridView1.SelectedRowsCount; i++)
            {
                if (gridView1.GetSelectedRows()[i] >= 0)
                    dtResult.ImportRow(gridView1.GetDataRow(gridView1.GetSelectedRows()[i]));
            }
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }
}
